package j01string;

import java.util.Arrays;

public class J1 {
    /*
    不可变，内存中的内容不可变
     */
    public static void main(String[] args) {
//        String s1 = "abc";
//        s1 += "x";
//        System.out.println("s1 = " + s1);


        char[] cArr = {'a','b','c'};
        String s1 = new String(cArr);

        System.out.println("s1 = " + s1);//abc
        cArr[0]='x';
        System.out.println("s1 = " + s1);//xbc -> abc
    }
}

class J2{
    public static void main(String[] args) {
        System.out.println("abc".indexOf("b"));//1
        System.out.println("abc".indexOf("bc"));//1
        System.out.println("abc".indexOf("ac"));//-1
        System.out.println("abc".indexOf("a",1));//-1
        System.out.println("====");
        System.out.println("ayxy".lastIndexOf("y"));//3
        System.out.println("ayxy".lastIndexOf("y",2));//1
        System.out.println("=替换==");
        String s1 = "axaxax0";
        String s2 = s1.replace("x","_");
        System.out.println("s1 = " + s1);
        System.out.println("s2 = " + s2);
        System.out.println(s1.replace("ax","$"));

        System.out.println("==字符分割==");
        String likes = "apple,xigua,xiangjiao";
        String[] likeArr = likes.split(",");
        System.out.println(Arrays.toString(likeArr));
        //
        System.out.println(String.join("_","abc","xt","yy"));

        String[] s100Arr = {"qq","ww","hh"};
        System.out.println(String.join("XX",s100Arr));

        System.out.println("==截取===");
        String s200 = "abcxyz";
        System.out.println(s200.substring(2));//cxyz
        System.out.println(s200.substring(2,4));//cx

        System.out.println("shenAo".toLowerCase());
        System.out.println("shenAo".toUpperCase());
    }
}
